﻿#region using
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace AwesomeTanks.Sources.GameElements
{
    /// <summary>
    /// Sprite is a class used to draw texture2D.
    /// </summary>
    public class Sprite
    {
        #region Fields

        public Texture2D Texture { get; set; }
        public Rectangle? SourceRectangle { get; set; } 
        public Vector2 Position { get; set; }
        public Vector2 Origin { get; set; }        
        public Color Color { get; set; }
        public float Rotation { get; set; }
        public float OldRotation { get; set; }
        public Vector2 Scale { get; set; }
        public SpriteEffects Effect { get; set; }
        public float LayerDepth { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Sprite"/> class.
        /// </summary>
        public Sprite()
        {
        }
        
        public Sprite(Texture2D texture, Rectangle? sourceRectangle, Vector2 position)
        {
            this.Position = position;
            this.SourceRectangle = sourceRectangle;
            this.Texture = texture;
            this.Color = Color.White;
            this.Rotation = 0;
            this.OldRotation = 0;
            this.Origin = Vector2.Zero;
            this.Scale = Vector2.One;
            this.Effect = SpriteEffects.None;
            this.LayerDepth = 0;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Draws this sprite in the specified sprite batch.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Texture, Position, SourceRectangle, Color, Rotation, Origin, Scale, Effect, LayerDepth);
        }

        #endregion
    }
}
